package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.WmNewsMessageConstants;
import com.heima.model.search.vos.SearchArticleVo;
import com.heima.search.service.ArticleSearch;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.search.SearchService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听kafka
 */
@Component
@Slf4j
public class SyncArticleListener {
    @Resource
    private ArticleSearch articleSearch;

    /**
     * 监听同步的kafka方法
     */
    @KafkaListener(topics = WmNewsMessageConstants.ARTICLE_ES_SYNC_TOPIC)
    public void getMessage(String message){
        log.info("坚挺到kafka收到消息开始");
        SearchArticleVo articleVo = JSON.parseObject(message, SearchArticleVo.class);
        articleSearch.custorm(articleVo);
        log.info("坚挺到kafka收到消息结束");
    }

}
